
;
(function(){
	'use strict';
	
	var app = angular.module('fwa.mainApp');
	app.controller('DrugStoreIllegalQueryCtrl',['$scope','$modal','CommunityService','DrugStoreIllegalService','Modal','InstitutionListService','BaseURL', 
	                                   function(scope,$modal,CommunityService,DrugStoreIllegalService,Modal,InstitutionListService,baseUrl) {
		
		scope.communityService = CommunityService;
		//CommunityService.initNewMedicalOrgInfoList();
		//判断是否已经查询过 机构信息 
		
		if (InstitutionListService.institutionMedicalOrgInfoList) {
			 scope.medicalOrgInfoList = InstitutionListService.institutionMedicalOrgInfoList;
		}
		else {
			InstitutionListService.initMedicalOrgInfoList("","","1").success(function(response){
	            scope.medicalOrgInfoList = response.medicalOrgList;
	            InstitutionListService.institutionMedicalOrgInfoList = response.medicalOrgList;
			});
		}
		
		var endDate = "";
		var startDate = "";
		CommunityService.initDate("yyyy-MM-dd").success(function(res){
			endDate = res.formatDate;
			startDate = CommunityService.lastYear(endDate);
			scope.form.date = {
								start: startDate,
								end: endDate
								};
		});
		scope.form = {};
		scope.loading = false;
		
		//获取参数
		function getParams() {
			var orgCode = scope.form.medicalOrgInfo.medicalOrgCode;
			scope.form.orgName = scope.form.medicalOrgInfo.medicalOrgName;
			var startDate = '', endDate = '';
			if (scope.form.date && scope.form.date.start) {
				startDate = scope.form.date.start;
			}
			if (scope.form.date && scope.form.date.end) {
				endDate = scope.form.date.end;
			}
			var params = {
					orgCode: orgCode,
					startDate: startDate,
					endDate: endDate,
					orgName: scope.form.orgName
				};
			return params;
		}
		
		//导出csv
		scope.exportFile =function (){
			var params = getParams();
			var url = baseUrl+"/drugStoreIllegal/exportDrugStoreIllegal.do?"+jQuery.param(params);
			window.location.href = url;
		}
		
		//鼠标移到div事件
		scope.mouseenter = function(rule) {
			rule.mouse = true;
		}
		
		//鼠标移出div事件
		scope.mouseleave = function(rule) {
			rule.mouse = false;
		}
		
		scope.nodesShow = true;
		//“+”展开
		scope.expand = function() {
			scope.nodesShow = !scope.nodesShow;
		}
		
		//查询
		scope.onSubmit = function() {
			query();
		}
		function query() {
			if (!scope.form.medicalOrgInfo) {
				scope.warnData = null;
				scope.auditData = null;
				scope.illegalWorkers = null;
				scope.rules = null;
				scope.form.orgName = null;
				Modal.alert("机构名称不能为空!!!");
				return false;
			}
			var params = getParams();
			scope.loading = true;
			DrugStoreIllegalService.query(params).success(function(res){
				scope.warnData = res.warnData;
				scope.auditData = res.auditData;
				scope.illegalWorkers = res.illegalWorkers;
				scope.loading = false;
			});
			//scope.warnData = {"num":100,"money":100,"list":[{"num":0,"name":"提醒","money":0,"code":"01"},{"num":0,"name":"书面预警","money":0,"code":"02"},{"num":0,"name":"约谈预警","money":0,"code":"03"},{"num":0,"name":"转稽核","money":0,"code":"04"},{"num":0,"name":"其它","money":0,"code":"09"}]};
			//scope.auditData = {"num":500,"money":500};
			//scope.illegalWorkers = {};
			scope.rules = [
			                {"result":"10001","name":"可疑","num":"865241","money":"17829613024"},
			                {"result":"10002","name":"高度可疑","num":"865241","money":"17829613024"},
			                {"result":"20001","name":"违规","num":"865241","money":"17829613024"}
			                ];
			scope.loading = false;
		}
		scope.onReset =function(){
			scope.form.medicalOrgInfo = null;
			scope.form.orgName = null;
			scope.warnData = null;
			scope.auditData = null;
			scope.illegalWorkers = null;
			CommunityService.initDate("yyyy-MM-dd").success(function(res){
				endDate = res.formatDate;
				startDate = CommunityService.lastYear(endDate);
				scope.form.date = {
									start: startDate,
									end: endDate
									};
			});
			
		}
		//点击查看预警详细
		scope.queryWarn = function(code) {
			var params = getParams();
			params.code = code;
			var queryWarnModal = $modal.open({
	      	      templateUrl: baseUrl + 'views/hcpms/evaluation/evaluationDrugStore/evaluationIllegal/illegal_modal.html',
	      	      backdrop:'static',
				  size:'sm',
	      	      controller: function($scope,$modalInstance) {
	      	    	 $scope.columns = [{label:"序号",map:"#",width:"8%",cellTemplate:'<span ng-bind="$index+1"></span>'},
		      			                  {label:"案发时间",map:"start_date",width:"12%"},
		      			                  {label:"预警编号",map:"warn_no",width:"12%"},
		      			                  {label:"预警原因",map:"reason",width:"22%"},
		      			                  {label:"机构记分额",map:"point",width:"12%"},
		      			                  {label:"确定不合理费用",map:"sumamount",width:"14%"},
		      			                  {label:"经办人",map:"agent",width:"10%"},
		      			                  {label:"审核人",map:"auditor",width:"10%"}
		      			                  ];
	      	    	DrugStoreIllegalService.querWarn(params).success(function(res){
		      	    		$scope.tableData=res.tableData;
		      	    	});
		      	     $scope.onOk = function() {
		      	    	$modalInstance.dismiss();
		      	    }
	      	      }
		      	});
		}
		
		//点击查看稽核详细
		scope.queryAudit = function() {
			var params = getParams();
			var queryWarnModal = $modal.open({
	      	      templateUrl: baseUrl + 'views/hcpms/evaluation/evaluationDrugStore/evaluationIllegal/illegal_modal.html',
	      	      backdrop:'static',
				  size:'sm',
	      	      controller: function($scope,$modalInstance) {
	      	    	  //表头
	      	    	  $scope.columns = [
	      	    	                  {label:"序号",map:"#",width:"8%",cellTemplate:'<span ng-bind="$index+1"></span>'},
	      			                  {label:"稽核时间",map:"audit_date",width:"12%"},
	      			                  {label:"案件号",map:"case_code",width:"12%"},
	      			                  {label:"事件要点",map:"key_point",width:"22%"},
	      			                  {label:"机构记分额",map:"case_code",width:"12%"},
	      			                  {label:"确定不合理费用",map:"total_deduction",width:"14%"},
	      			                  {label:"经办人",map:"created",width:"10%"},
	      			                  {label:"审核人",map:"created",width:"10%"}
	      			                  ];
	      	    	DrugStoreIllegalService.queryAudit(params).success(function(res){
		      	    		$scope.tableData=res.tableData;
		      	    	});
		      	     $scope.onOk = function() {
		      	    	$modalInstance.dismiss();
		      	    }
	      	      }
		      	});
		}
	}]);
})();